import React, { useState, useEffect } from "react";
import Header from "../../components/Header/Header";
import {
  reqgetcate,
  reqgetbanner,
  reqgetindexgoods,
  reqgetgroupon,
  reqgetnew,
} from "../../http/api";
import Cate from "./components/Cate/Cate";
import Goods from "./components/Goods/Goods";
import Banner from "./components/Banner/Banner";
import New from "./components/New/New";
import Groupon from "./components/Groupon/Groupon";
const Home = () => {
  const [cate, setCate] = useState([]);
  const [goods, setGoods] = useState([]);
  const [banner, setBanner] = useState([]);
  const [groupon,setGroupon] = useState([]);
  const [news, setNews] = useState([]);
  const [n,setn] = useState(0);

  useEffect(() => {
    reqgetcate().then((res) => {
      setCate(res.data.list);
    });
    reqgetbanner().then((res) => {
      setBanner(res.data.list);
    });
    reqgetnew().then((res) => {
      setNews(res.data.list);
    });
    reqgetindexgoods().then((res) => {
      setGoods(res.data.list);
    });
    reqgetgroupon().then((res) => {
      setGroupon(res.data.list);
    });
  },[]);
  return (
    <div>
      <Header title="首页"></Header>
      <Cate cate={cate}></Cate>
      <New news={news}></New>
      <Groupon groupon={groupon}></Groupon>
      <Banner banner={banner}></Banner>
      <Goods goods={goods} n={n} onChangeN={(v) => setn(v)}></Goods>
    </div>
  );
};
export default Home;
